﻿using System;
using Castle.MonoRail.Framework;
using Castle.MonoRail.ViewComponents;
using StateTheaterDataModel;
using System.Configuration;


namespace StateTheater.Component
{
	public class AdComponent : ViewComponentEx
	{
		[ViewComponentParam]
		public string  Location { get; set; }

		[ViewComponentParam(Default="adcode")]
		public string AdCodeKey { get; set; }

		public Random RNG { get; set; }

		public override void Render()
		{
			PropertyBag["adcode"] = ConfigurationManager.AppSettings[AdCodeKey];
			switch (Location.ToLowerInvariant())
			{
				case "bottom":
					PropertyBag["code"] = String.Format("{0:00}{1:000}", RNG.Next(10,100), RNG.Next(100,1000));
					this.RenderView("bottom");
					break;

				case "above":
					this.RenderView("above");
					break;

				case "skyscraper":
					this.RenderView("skyscraper");
					break;

				case "box300x250":
					this.RenderView("box300x250");
					break;

				case "cube125x125":
					this.RenderView("cube125x125");
					break;
			}


		}

	}
}
